
from generate_panel_image import PanelImage
from custom_logger import PrefixDateLogger
from email_send import  SendEmail
from generate_mail_table import CpaData
import time  # 导入time模块，用于添加延迟
# -------------------------- 配置参数（必须修改）--------------------------

# ------------------------------------------------------------------------
logger = PrefixDateLogger("send_data_email")
# 执行脚本
if __name__ == "__main__":
    # 创建连接实例
    panel_image = PanelImage()
    email=SendEmail()
    cpa = CpaData()
    dau_dnu_data=cpa.get_active_new_data()
    image_path = panel_image.general_image("adztqbf",
                                           "overview",
                                           None,
                                           1600)
    logger.info(f"image_path:{image_path}")
    if image_path:

        # 邮件正文（支持HTML）
        body = f"""
        
        <p>下面表格是活跃数据报表：</p>
        <p>{dau_dnu_data}</p>
        <p>附件为仪表盘截图，可查看详细数据趋势：</p>
        <p><a href="http://47.245.149.255:3000/public-dashboards/75e93a4de56f470c9ecf129a5612df39">点击跳转至Grafana在线查看</a></p>
        """
        title="最近7天活跃数据报表"
        email.send_email_with_attachment(title,body,image_path)
